package com.rambler.common.utils;

import org.apache.commons.codec.digest.DigestUtils;

import java.io.InputStream;

/**
 * @author suhao
 */
public class FileUtil {

    public static String calculateMd5(InputStream inputStream) {
        try {
            return DigestUtils.md5Hex(inputStream);
        } catch (Exception e) {
            throw new RuntimeException("计算MD5失败", e);
        }
    }

    public static String calculateSha1(InputStream inputStream) {
        try {
            return DigestUtils.sha1Hex(inputStream);
        } catch (Exception e) {
            throw new RuntimeException("计算SHA1失败", e);
        }
    }

    // 获取扩展名
    public static String getExtension(String fileName) {
        return fileName.substring(fileName.lastIndexOf(".") + 1);
    }

}
